home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 September / macformat-004.iso / MacFormat 16 Cover Disk / HomePublisher Demo / AHP Pouch / Additions / Caption Graphics / Caption Selected Graphics… / Caption Selected Graphics…
Encoding:
Text File  |  1993-09-29  |  12.2 KB  |  432 lines  |  [SGPA/SCPG]

  1. on startup
  2.  
  3. if toolmode = "texttool" then
  4. answer "Select one or more graphic objects with the arrow tool."
  5. exit startup
  6. end if
  7.  
  8. set shuffleTextObjects to false
  9.  
  10. set lockcursor to true
  11. set mousecursor to watch
  12. set lockscreen to true
  13.  
  14. progressDialog open
  15. progressDialog show, "Searching for Captionable graphics…"
  16. put true into zoomed
  17. put toolmode into oldTool
  18. put currentpage into theOldPage
  19. put 0 into totalCaptions
  20. put displayGuides into oldGuides
  21. set displayGuides to true
  22. put 25 into CaptionVSize -- In points.
  23. put false into MadeCaptions -- Any captions made yet?
  24.  
  25. put measurements into OldMeasurements
  26. set measurements to points
  27.  
  28. -- Assign data to objects
  29. repeat with x = 1 to number of items in selectedObjects()
  30. if kind of object item x of selectedObjects() = "Grayscale Graphic" or¬
  31. kind of object item x of selectedObjects() = "PICT Graphic" or ¬
  32. kind of object item x of selectedObjects() = "eps graphic" or¬
  33. kind of object item x of selectedObjects() = "bitmap graphic" or¬
  34. kind of object item x of selectedObjects() = "quicktime Movie" or¬
  35. kind of object item x of selectedObjects() = "rectangle" or¬
  36. kind of object item x of selectedObjects() = "oval" or¬
  37. kind of object item x of selectedObjects() = "rounded rectangle" then
  38.  
  39. put 1+totalCaptions into TotalCaptions
  40. -- Pre-Assign text of caption
  41. set itemdel to numtochar(1)
  42. put "Type Caption for Graphic here." into item TotalCaptions of TextOfCaptions
  43. set itemdel to ","
  44.  
  45. -- Assign Page of Caption Graphic.
  46. put currentPage into item totalCaptions of pagesOfCaptions
  47. -- Assign Caption Graphic Object Number of the page.
  48. put (item x of selectedObjects()) into item totalCaptions of CaptionObjects
  49. -- Assign name of Caption Object
  50. put "Caption " & ticks() into theCaptionName
  51. put theCaptionName into item totalCaptions of CaptionTextObjNames
  52. -- Assign name of Caption Story
  53. put theCaptionName & ".S" into item totalCaptions of CaptionStoryNames
  54. -- Assign name of Caption Line Object
  55. put theCaptionName & ".L" into item totalCaptions of CaptionLineNames
  56. end if
  57. end repeat
  58. progressDialog close
  59.  
  60. set measurements to OldMeasurements
  61.  
  62. if totalCaptions < 1 then 
  63. answer "No graphic objects are selected. Select the graphics to caption."
  64. set toolmode to oldtool
  65. set currentpage to theoldPage
  66. set measurements to oldMeasurements
  67. exit startup
  68. end if
  69.  
  70.  
  71. -- Run the dialog.
  72.  
  73. put dialog(preload, 506) into theDialog
  74.  
  75. -- Action proc for Headline Entry Box
  76. SetDialogItem 6, Box
  77. -- Action proc for Create Caption box.
  78. SetDialogItem 23, Box
  79. -- Action proc for Text Proxie
  80. SetDialogItem 11, Box
  81. -- Action for graphic preview
  82. SetDialogItem 2, Box 
  83.  
  84.  
  85. put 1 into CurrentCaption
  86. setDialogItem 5, set
  87.  
  88. repeat forever -- Do all caption objects.
  89. put true into DoUpdate
  90.  
  91. -- Handle the dialog.
  92. repeat forever
  93.  
  94. -- Check if we need to update the dialog data.
  95. if DoUpdate then 
  96.  
  97. -- If the user has made any changes, add "…" to cancel button
  98. if MadeCaptions then
  99. setDialogItem 19,contents, "Cancel…"
  100. end if
  101.  
  102. -- Get current Captions' Data
  103. set itemdel to numtochar(1)
  104. setDialogItem 5, contents, item currentCaption of TextOfCaptions
  105. set itemdel to ","
  106.  
  107. -- Go to the Captions' page
  108. set currentpage to item currentCaption of pagesOfCaptions
  109. put item currentCaption of CaptionObjects into theCaptionObject
  110.  
  111. -- Caption off page? or Too many objects?
  112. set measurements to points
  113. if number(objects) > 197 then 
  114. put true into TooManyObjects
  115. else
  116. put false into TooManyObjects
  117. end if
  118.  
  119. put rect of object (item currentCaption of CaptionObjects) into theObjRect
  120. if (item 4 of theObjRect) + CaptionVSize > pageHeight then
  121. put true into CaptionOffPage
  122. else
  123. put false into CaptionOffPage
  124. end if
  125.  
  126. if TooManyObjects or CaptionOffPage then
  127. setDialogItem 21, disabled
  128. if TooManyObjects then
  129. setDialogItem 13, text, cr & cr & "Adding a caption would exceed "&¬
  130. "the maximum number of objects allowed on a page. Delete some objects "¬
  131. and try this addition again."
  132. else
  133. setDialogItem 13, text, cr & cr & "There is not enough room to place "&¬
  134. "a caption below this graphic. Please move or resize the graphic object."
  135. end if
  136. else
  137. setDialogItem 21, enabled 
  138. setDialogItem 13, disabled
  139. end if -- Caption off page?  
  140.  
  141.  
  142. setDialogItem 9, graphic, theCaptionObject & ",p"
  143.  
  144. -- Is there an object for caption text preview?
  145. set measurements to points
  146. if exists(object (item currentCaption of CaptionTextObjNames)) then
  147. put number of object (item currentCaption of CaptionTextObjNames) into¬
  148. CaptionTextObj
  149. -- Preset the text of the caption
  150. SetDialogItem 13, graphic, CaptionTextObj & ",p"
  151. SetDialogItem 21, set -- Make a caption.
  152. SetDialogItem 22, clear -- dont Make a caption.
  153. setDialogItem 16, enabled -- Include Dividing Line
  154. setDialogItem 15, enabled -- Update Text Preview
  155. else
  156. SetDialogItem 21, clear -- Make a caption.
  157. SetDialogItem 22, set -- dont Make a caption.
  158. setDialogItem 16, disabled -- Include Dividing Line
  159. setDialogitem 15, disabled -- Update Text Preview
  160. end if
  161. set measurements to oldMeasurements
  162.  
  163. -- Show current page number
  164. setDialogItem 18, contents, currentpage
  165.  
  166. -- Is there a caption on the page yet?
  167. if exists( object (item currentCaption of CaptionTextObjNames) ) then
  168. setDialogItem 21, set -- create a caption
  169. setDialogItem 22, clear -- Dont create a caption.
  170. set itemdel to numtochar(1)
  171. --set caption text entry.
  172. setDialogItem 5, contents, item currentCaption of TextOfCaptions
  173. set itemdel to ","
  174. -- Set text preview.
  175. setDialogItem 13, graphic, ¬
  176. number of object (item currentCaption of CaptionTextObjNames) & ",p"
  177. else
  178. setDialogItem 22, set -- dont create a caption
  179. setDialogItem 21, clear -- Create a caption
  180. set itemdel to numtochar(1)
  181. --set caption text entry.
  182. setDialogItem 5, set, contents, item currentCaption of textOfCaptions
  183. set itemdel to ","
  184. setDialogItem 15, disabled -- UpdateTextPreview
  185. end if
  186.  
  187.  
  188. -- Set state of navigator buttons (Prev & Next)
  189. if totalCaptions < 2 then
  190. setDialogItem 20, disabled
  191. setDialogItem 14, disabled
  192. else
  193. if currentCaption = 1 then
  194. setDialogItem 20, disabled
  195. setDialogItem 14, enabled
  196. end if
  197. if CurrentCaption = totalCaptions then
  198. setDialogItem 20, enabled
  199. setDialogItem 14, disabled
  200. end if
  201. if (currentCaption ≠ 1) and (currentCaption ≠ totalCaptions) then 
  202. setDialogItem 20, enabled
  203. setDialogItem 14, enabled
  204. end if
  205. end if
  206.  
  207. -- Force update of text preview
  208. setDialogItem 2, box
  209. if exists(object (item currentCaption of CaptionTextObjNames)) then
  210. SetDialogItem 13, graphic, ¬
  211. number of object (item currentCaption of CaptionTextObjNames) & ",p"
  212. end if
  213.  
  214. -- Force update of Graphic to Caption
  215. SetDialogItem 9, graphic, item currentCaption of CaptionObjects & ",p"
  216. set measurements to oldMeasurements
  217. put false into DoUpdate
  218. end if -- Do Update
  219.  
  220.  
  221. get dialog(display, theDialog)
  222. set lockcursor to true
  223. Set mousecursor to "watch"
  224.  
  225. switch it
  226.  
  227. case 22 -- No Caption.
  228. -- Delete Caption Object
  229. if exists(object (item currentCaption of CaptionTextObjNames)) then
  230. delete object (item CurrentCaption of CaptionTextObjNames)
  231. end if
  232. -- Delete Caption Line Object
  233. if exists(object (item currentCaption of CaptionLineNames)) then
  234. delete object (item currentCaption of CaptionLineNames)
  235. end if
  236.  
  237. setDialogItem 15, disabled
  238. setDialogItem 11, box -- Text Preview, force update
  239. setDialogItem 16, disabled
  240. put true into DoUpdate
  241. exit switch
  242.  
  243. case 21 -- Create Caption.
  244. set itemdel to numtochar(1)
  245. put contentsOf(item5) into item CurrentCaption of textOfCaptions
  246. set itemdel to ","
  247. put true into MadeCaptions
  248. -- Create Caption text object & line.
  249. if not exists(object (item currentCaption of CaptionTextObjNames)) then
  250. set measurements to points
  251. put rect of object (item currentCaption of CaptionObjects) into theCaptionRect
  252. set stylerecomposition to false
  253. open story item currentCaption of CaptionStoryNames
  254. draw rectangle from item 1 of theCaptionRect, item 4 of theCaptionRect to ¬
  255. item 3 of theCaptionRect, item 4 of theCaptionRect + CaptionVSize
  256. close story
  257. set name of last object to (item currentCaption of CaptionTextObjNames)
  258. set linePattern of last object to 0
  259. set fillPattern of last object to 2
  260. set frameLineType of last object to 1
  261. set textwrap of last object to 20 aroundRect 
  262. set stylerecomposition to true
  263. set itemdel to numtochar(1)
  264. put item CurrentCaption of textOfCaptions into theStoryText
  265. set itemdel to ","
  266. put theStoryText into story item currentCaption of CaptionStoryNames
  267. copyfit story (item currentCaption of CaptionStoryNames)
  268. set measurements to oldMeasurements
  269. -- Update text preview.
  270. setDialogItem 9, graphic, ¬
  271. number of object (item currentCaption of CaptionTextObjNames) & ",p"
  272. end if
  273. put true into DoUpdate
  274. exit switch
  275.  
  276. case 19 -- Cancel
  277. -- Check if user made any captions...
  278.  
  279. put true into CancelNow
  280. if MadeCaptions then 
  281. answer "Cancelling now will erase all captions that have been entered. Do you" &¬
  282. " really want to cancel?" with "Yes" or "No"
  283. if it is "yes" then
  284. progressDialog open
  285. set lockscreen to true
  286. set styleRecomposition to false
  287. repeat with c = 1 to totalCaptions
  288. progressDialog show, "Deleting Caption " & c & " of " & totalCaptions & "…"
  289.  
  290. -- Goto Page of Caption.
  291. set currentPage to item c of pagesOfCaptions
  292. -- Delete Caption Object
  293. if exists(object (item c of CaptionTextObjNames)) then
  294. delete object (item c of CaptionTextObjNames)
  295. end if
  296. -- Delete Caption Line Object
  297. if exists(object (item c of CaptionLineNames)) then
  298. delete object (item c of CaptionLineNames)
  299. end if
  300. end repeat -- c=1 to totalcaptions
  301. progressDialog close
  302. set lockscreen to false
  303. put true into CancelNow
  304.  
  305. else 
  306. put false into CancelNow
  307. end if -- it = yes
  308. end if -- madeCaptions?
  309.  
  310. if CancelNow then
  311. set styleRecomposition to true
  312. set currentPage to theoldPage
  313. set toolmode to oldTool
  314. set measurements to oldMeasurements
  315. exit startup
  316. end if
  317. exit switch
  318.  
  319. case 20 -- Prev Caption
  320. case 14 -- Next Caption
  321. case 10 -- OK Button
  322. case 15 -- Update Text Preview
  323. -- Set the text of the caption & Store the text into the list.
  324. if hilited(item21) then
  325. put contentsOf(item5) into newCaptionText
  326. set itemdel to numtoChar(1)
  327. put newCaptionText into item CurrentCaption of textOfCaptions
  328. set itemdel to ","
  329. put newCaptionText into story (item currentCaption of CaptionStoryNames)
  330. copyfit story (item currentCaption of CaptionStoryNames)
  331. end if
  332.  
  333. if it = 15 then
  334. setDialogItem 9, graphic, ¬
  335. number of object (item currentCaption of CaptionTextObjNames) & ",p"
  336. end if
  337.  
  338. case 16 -- Include dividing line?
  339. if it = 16 then 
  340. put hilited(item16) into dividingLine
  341.  
  342. if dividingLine then
  343. set measurements to points
  344. -- Create the dividing line
  345. if not exists(object (item currentCaption of CaptionLines)) then
  346. draw line from (item 1 of theCaptionRect), ¬
  347. (item 4 of theCaptionRect+CaptionVSize-1)¬
  348. to (item 3 of theCaptionRect), (item 4 of theCaptionRect+CaptionVSize-1)
  349. set frameLineType of last object to 1
  350. set linepattern of last object to 1
  351. set name of last object to (item currentCaption of CaptionLineNames)
  352. set measurements to oldMeasurements
  353. end if
  354. else
  355. -- Delete dividing line.
  356. if exists(object (item currentCaption of CaptionLines)) then
  357. delete object (item currentCaption of CaptionLines)
  358. end if
  359. end if -- dividing line?
  360.  
  361. end if -- it=16
  362.  
  363. if it = 10 then exit repeat -- OK Button
  364. if it = 20 then -- Prev
  365. put contentsOf(item5) into StoryText
  366. set itemdel to numtoChar(1)
  367. put StoryText into item CurrentCaption of textOfCaptions
  368. set itemdel to ","
  369. put currentCaption - 1 into CurrentCaption
  370. if currentCaption < 1 then put 1 into CurrentCaption
  371. setDialogItem 5,set
  372. end if
  373. if it = 14 then -- Next
  374. put contentsOf(item5) into StoryText
  375. set itemdel to numtoChar(1)
  376. put StoryText into item CurrentCaption of textOfCaptions
  377. set itemdel to ","
  378. put currentCaption + 1 into CurrentCaption
  379. if currentCaption > totalCaptions then put totalCaptions into currentCaption
  380. setDialogItem 5, set
  381. end if
  382. SetDialogItem 11, box -- Text Preview Box.
  383.  
  384.  
  385. case 25
  386. if it = 25 then
  387. helpdialog 128, "Caption Help"
  388. end if
  389.  
  390. put true into DoUpdate
  391. exit switch
  392.  
  393. end switch -- Item Hit (it)
  394.  
  395. end repeat -- Dialog Handler.
  396.  
  397. if it = 10 then exit repeat -- Ok Button.
  398. end repeat -- Every Caption.
  399.  
  400. set displayGuides to oldGuides
  401. set toolmode to oldTool
  402. set currentPage to theoldPage
  403. set measurements to oldMeasurements
  404.  
  405. End startup
  406.  
  407. function contentsof thedata
  408. put itemdel into OldItemDel
  409. set itemdel to "\"
  410. get item 2 of thedata
  411. set itemdel to OldItemDel
  412. return it
  413. end contentsof
  414.  
  415. function hilited thedata
  416. return (char 4 of thedata = "s")
  417. end hilited
  418.  
  419. on help
  420. put  dialog (preload, 128) into thedialog
  421. put "---a\0" into item2
  422. put "---a\1" into item3
  423. put "---a\2" into item4
  424.  
  425.  
  426. repeat forever
  427. get dialog(display, thedialog)
  428. if (it = 1) then exit repeat
  429. end repeat
  430. get dialog(dispose, thedialog)
  431. end help
  432.     ıH<BÏ